from tkinter import *
import cv2
from PIL import Image,ImageTk
# from video_cap import state

def fenlei():
    print("垃圾分类成功！")
state="系统加载中……！"
new_width=500
new_height=500
class Mywindow():
    def __init__(self,queue,master):
        self.root=master
        self.queue=queue

        # self.squeue=squeue
        self.root.title("垃圾识别系统——河大AI小分队")
        self.root.geometry('1200x700')
        self.root.configure(bg="#ADD8E6")
        self.image=None
        self.state=None
        self.label2 = Label(self.root, text="河南大学人工智能学院—AI小分队", font=('宋体', 10, 'bold '),
                       bg="#7CCD7C",
                       width=70, height=1, padx=5, pady=15, borderwidth=5, relief="sunken")

        self.label3 = Label(self.root, text="垃圾分类系统", font=('宋体', 15, 'bold italic'),
                       bg="#7CCD7C",
                       width=51, height=1, padx=5, pady=8, borderwidth=5, relief="sunken")
        self.label2.pack()
        self.label3.pack()
        self.label = Label(self.root, image=self.image)
        self.label.pack()


        self.label4 = Label(self.root,
                       text="-------------------------------------------------------------------------------------------------------",
                       bg="#ADD8E6")
        self.label4.pack()
        self.button1=Button(self.root, text="垃圾已就位，开始分类", command=fenlei)
        self.button1.pack()

        self.label5 = Label(self.root, text=self.state, font=('宋体', 20, 'bold '), width=70, height=2, padx=10, pady=15,
                       borderwidth=5, bg="#ADD8E6")
        self.label5.pack()

        self.update_image()

    def update(self):

        image = self.queue.get()[0]
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        image = Image.fromarray(image)
        image = image.resize((new_width, new_height))
        image = ImageTk.PhotoImage(image)
        state=self.queue.get()[1]

        return image,state




    def update_image(self):
        self.image,self.state=self.update()
        self.label.config(image=self.image)
        self.label5.config(text=self.state)
        self.label.image = self.image
        self.label5.text=self.state
        self.root.update()  # 更新界面
        self.root.after(100, self.update_image)

if __name__=="__main__":
    root = Tk()
    image_path="C:/Users/86167/Desktop/program/garbage/garbage/1/img_331.jpg"
    image=Image.open(image_path)
    image = image.resize((new_width, new_height))
    image=ImageTk.PhotoImage(image)
    app=Mywindow(image,root)
    root.mainloop()
